namespace 算术练习
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            NewQuestion();
            this.input.Value = new Decimal();
        }
        Random random = new();
        int sorce = 0;
        QuestionType questionType = QuestionType.AdditionAndSubtractionWithin10;
        int randomMax = 10;
        int sorceItem = 1;//当前题目得分
        int resultItem = 0;//当前题答案
        bool submit = false;//当前题是否已经提交过了
        bool showAnswer = true;//答错自动显示答案
        public enum QuestionType
        {

            AdditionAndSubtractionWithin10,// 10以内加减法
            AdditionAndSubtractionWithin20,// 10以内加减法
            Multiplication//乘法
        }
        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            var radio = sender as RadioButton;
            string xing = "★";
#pragma warning disable CS8602
            switch (radio.Name)
            {
                case "radio_type1":
                    sorceItem = 1;
                    questionType = QuestionType.AdditionAndSubtractionWithin10;
                    randomMax = 10;
                    break;
                case "radio_type2":
                    sorceItem = 2;
                    questionType = QuestionType.AdditionAndSubtractionWithin20;
                    xing = "★★";
                    randomMax = 20;
                    break;
                default:
                    sorceItem = 3;
                    questionType = QuestionType.Multiplication;
                    xing = "★★★";
                    break;
            }
            this.label_sorce_xing.Text = xing;
            this.label_score_item.Text = sorceItem.ToString();
            //切换难度后需要自动生成新题
            NewQuestion();

        }
        //生成新题 TODO
        private void NewQuestion()
        {
            submit = false;
            var num1 = random.Next(randomMax);
            var num2 = random.Next(randomMax);

            switch (questionType)
            {
                case QuestionType.AdditionAndSubtractionWithin10:
                case QuestionType.AdditionAndSubtractionWithin20:
                    int t = random.Next(2);
                    if (t == 0)
                    {
                        resultItem = num1 + num2;
                        this.label_operator.Text = "+";
                    }
                    else
                    {
                        resultItem = num1 - num2;
                        this.label_operator.Text = "-";
                    }
                    break;
                default:
                    resultItem = num1 * num2;
                    this.label_operator.Text = "*";
                    break;
            }
            this.label_num1.Text = num1.ToString();
            this.label_num2.Text = num2.ToString();
            this.label_result.Text = "";
            this.label1.Text = "题目解析:";
        }
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            this.timer1.Interval = (int)this.interval.Value * 1000;
        }
        private void Interval_MouseCaptureChanged(object sender, EventArgs e)
        {
            MessageBox.Show("safd1");
        }
        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }


        private void button2_Click(object sender, EventArgs e)
        {
            if (submit)
            {
                MessageBox.Show("已经提交过了!不要重复提交");
                return;
            }
            var i = (int)this.input.Value;
            if (resultItem == i)
            {
                //答对了
                submit = true;
                sorce += sorceItem;
                this.label_score.Text = sorce.ToString();
                this.label_result.Text = "√";
                label_result.ForeColor = Color.Lime;
                if (showAnswer)
                    this.label1.Text = "题目解析:答对了就不用解析了,难道你是瞎蒙的?";
                return;
            }
            //答错了
            label_result.ForeColor = Color.Red;
            this.label_result.Text = "X";
            if (showAnswer)
                this.label1.Text = $"错题解析:答案是{resultItem},是不是难到你了?";
            else
                this.label1.Text = "错题解析:是你不要答案的,再仔细思考思考.";
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            showAnswer = checkBox2.Checked;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            NewQuestion();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            NewQuestion();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            this.timer1.Enabled = this.checkBox1.Checked;
        }

        private void input_ValueChanged(object sender, EventArgs e)
        {

        }
    }
}
